<?php
    defined('_JEXEC') or die(); 
    JHTML::_('behavior.tooltip'); 
    $listOrder    = @$this->lists['order'];
    $listDirn    = @$this->lists['order_Dir'];
?>
<style>
    .svoucher {
		cursor: pointer;
		-moz-box-shadow:inset 0px 1px 0px 0px #dcecfb;
		-webkit-box-shadow:inset 0px 1px 0px 0px #dcecfb;
		box-shadow:inset 0px 1px 0px 0px #dcecfb;
		background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #bddbfa), color-stop(1, #80b5ea) );
		background:-moz-linear-gradient( center top, #bddbfa 5%, #80b5ea 100% );
		filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#bddbfa', endColorstr='#80b5ea');
		background-color:#bddbfa;
		-moz-border-radius:6px;
		-webkit-border-radius:6px;
		border-radius:6px;
		border:1px solid #84bbf3;
		display:inline-block;
		color:#ffffff;
		font-family:arial;
		font-size:12px;
		font-weight:bold;
		padding:4px 10px;
		text-decoration:none;
		text-shadow:1px 1px 0px #528ecc;
}.svoucher:hover {
	background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #80b5ea), color-stop(1, #bddbfa) );
	background:-moz-linear-gradient( center top, #80b5ea 5%, #bddbfa 100% );
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#80b5ea', endColorstr='#bddbfa');
	background-color:#80b5ea;
}.svoucher:active {
	position:relative;
	top:1px;
}
a.svoucher:hover {text-decoration: none;}
img.calendar {float: right;}
	#tbl_filter{
        margin: 0 ; padding: 0 ;
    }
    #tbl_filter td{
        padding: 3px;
    }
    #tbl_filter input, #tbl_filter img {
        float: left;
        margin: 0 5px 0 0;
        width: auto;
    }
    .outlet-list, .outlet-list-extra { display: none; }    
    .date-from-to { border-bottom: 1px solid #CCC; padding-bottom: 3px; font-size: 1.4em; }
    .date-from-to span { color: #e72222; }
    table.adminlist thead th { padding: 8px; }
</style>
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root(); ?>js/multiselect/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root(); ?>js/multiselect/jquery-ui.css" />
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/multiselect/jquery.multiselect.js"></script>

<script language="javascript" type="text/javascript">
    function submitform(pressbutton){
        var form = document.adminForm ;
        //alert(pressbutton)
        if (pressbutton)
        {
            form.task.value=pressbutton ;
        }
        if ((pressbutton=='send_redemp_notice_email')||(pressbutton=='send_redemp_pick_up_notice')){
              form.controller.value="reports" ;
        }
        form.submit();
    }
    jQuery(function(){
        jQuery("#extra_status").attr({"multiple":false, "size":1}); 
	
		jQuery("a.svoucher").click(function(){
			var id = jQuery(this).attr('rel');
			jQuery("#save_"+id).hide();
			//var outlet_name = jQuery("#outlet_"+id).find("option:selected").text();
			var outletCode = jQuery("#outlet_"+id).find("option:selected").val();
			var date = jQuery("#date"+id).val();
			//alert(outletCode);return false;
			if(outletCode == 0){alert("Please chose outlet");return false;}
			if(date == 0){alert("Please chose date use outlet");return false;}
			else {
				jQuery("#loading_"+id).show();
				jQuery.ajax({
					url: "index.php?option=com_wrd&controller=reports&task=savePickup",
					type: "POST",
					data: 'id='+id+'&outletCode='+outletCode+'&date='+date,
					success: function (res) {
						if(res) {
							jQuery("#loading_"+id).hide();
							jQuery("#save_"+id).show().text("Saved").css("color","blue");
							//alert(res);
						}
						else {
							alert("Error save voucher");
							jQuery("#save_"+id).show().text("error").css("color","red");
						}
					}		
				});
			}
		});

    });
</script>
<div class="col width-100">    
        <div id="editcell">
            <form action="<?php echo JRoute::_("index.php?option=com_wrd&controller=reports")?>" method="post" name="filterform" >
                <table style='margin-bottom:5px' id="tbl_filter">
                    <tbody>
                        <tr>
                            <td align="left" valign="bottom" style="border-right: 1px solid #d0d0d0;">
                                <table >
                                    <tr valign="top">
                                        <td valign="top" width='35px'>From</td>        
                                        <td valign="top" width='150px'>
                                            <?php
                                                echo JHTML::_ ( 'calendar', ($this->pr['date_from'] != '') ? $this->pr['date_from'] : date('Y-m-d', mktime(0, 0, 0, date('m'), 1, date('Y'))), 'date_from', 'date_from', '%Y-%m-%d');
                                            ?>
                                        </td>
                                       
                                    </tr>
                                    <tr>
                                        <td width='35px'>To</td>        
                                        <td width='150px'>
                                            <?php
                                                echo JHTML::_ ( 'calendar', ($this->pr['date_to'] != '') ? $this->pr['date_to'] : date('Y-m-d', time()), 'date_to', 'date_to', '%Y-%m-%d');
                                            ?>
                                        </td>
                                      
                                    </tr>
                                </table>
                            </td>
                            <td align="left" valign="middle" style="border-right: 1px solid #d0d0d0;">
                                <table >
                                    <tr>
                                        <td>Status: </td>
                                        <td style="width: 230px;">
                                            <?php echo $this->lists['extra_status'] ; ?>                                            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            &nbsp;
                                        </td>
                                        <td style="text-align: left ;">
                                            <input type="submit" name="summary" onclick="document.getElementById('submitViewExcel').value = 'submitViewExcel';  document.getElementById('task').value = 'membershipclub';" value="Summary" />
                                            <input type="submit" name="detail" onclick="document.getElementById('submitViewExcel').value = 'submitViewExcel';  document.getElementById('task').value = 'membershipclubdetail';" value="Detail" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                                                        
                            <td align="left" valign="bottom">
                                <table >
                                    <tr>
                                        <td>
                                             Top: 
                                        </td>
                                        <td>
                                            Choose: 
                                            <select name="topDisplaySelect" id="topDisplaySelect">
                                                <option value="10">10</option>
                                                <option value="20">20</option>
                                                <option value="50">50</option>
                                                <option value="100">100</option>
                                                <option value="">All</option>
                                            </select>&nbsp;or type&nbsp;
                                            <input name="topDisplaytbx" id="topDisplaytbx" type="text" style="width: 60px; float: none;" />
                                        </td>
                                    </tr>
                                    <tr>
                                        
                                        <td>
                                            &nbsp;
                                        </td>
                                        <td style="text-align: left ;padding: 10px 0 0;">                                            
                                            <input type="submit" id="exportexcelsummary" name="exportexcelsummary" onclick="document.getElementById('task').value = 'exmembershipclub'" value="Export summary excel" />
                                            <input type="submit" id="exportexceldetail" name="exportexceldetail" onclick="document.getElementById('task').value = 'exmembershipclubdetail'" value="Export detail excel" />
                                        </td>
                                    </tr>
                                </table>
                            </td>                            
                        </tr>
                    </tbody>
                </table>
                <input type="hidden" name="controller" value="reports" />
                <input type="hidden" name="option" value="com_wrd" />
                <input type="hidden" name="submitViewExcel" id="submitViewExcel" value="" />
                <input type="hidden" name="task" id="task" value="" />
            </form>    
            <br />
            <h3 class="date-from-to"><span style="float: right;">Total: <?php echo $this->total; ?></span><?php echo $this->lists['date'] ?></h3>
            <form  id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd&controller=reports")?>" method="post" name="adminForm" >
                <table width="100%" class="adminlist">
                    <thead>
                        <tr>
                             <th width="3%">
                                &nbsp;
                            </th>
                            <th nowrap="nowrap">
                                Member ID
                             </th> 
							<th nowrap="nowrap">
                                Title
                             </th> 							 
                            <th nowrap="nowrap">  
                                 Name
                             </th>
                            <th nowrap="nowrap">  
                                 Email
                             </th>
                             <!-- 3 -->   
                             <th nowrap="nowrap">Phone</th>
                             <th nowrap="nowrap">Job</th> 
                             <th nowrap="nowrap">Company name</th>
							 <th nowrap="nowrap">Pick up date</th>
                             <th nowrap="nowrap">Pick up at outlet</th> 
                             <th nowrap="nowrap">Action</th>	
                             
                        </tr>
                    </thead>                    
                    <tbody>
                         <?php //echo '<pre>';print_r($this->items);
                               $k = 0;
                               if(count($this->items) > 0): 
                                for ($i=0, $n= count( $this->items ); $i < $n; $i++):
                                    $row = &$this->items[$i];
                                    $checked     = JHTML::_('grid.checkedout',   $row, $i);
                            ?>    
                                 <tr class="<?php echo "row$k"; ?>" >
                                    <td>
                                        <?php echo $checked; ?>
                                    </td>
                                    <td>
                                        <?php echo 'V'.$row->member_id; ?>
                                    </td>
									<td>
                                        <?php echo $row->prefix; ?>
                                    </td>
                                    <td>
                                        <a href="index.php?option=com_wrd&controller=profile&id=<?php echo $row->profile_id ?>&layout=form">
                                            <?php echo $row->l_name.' '.$row->f_name; ?>
                                        </a>
                                    </td>
                                    <td>
                                        <?php echo $row->email; ?>
                                    </td>
                                    
                                    <!-- 3 -->
                                    <td>
                                        <?php echo $row->phone; ?>
                                    </td>
                                    <td>
                                        <?php echo $row->job; ?>
                                    </td>
                                    <td>
                                        <?php echo $row->company_name; ?>
                                    </td>
									<td style="width: 132px;"><?php echo JHTML::_ ( 'calendar', ($row->pick_up_date != '') ? $row->pick_up_date : '', 'date'.$row->profile_id, 'date'.$row->profile_id, '%Y-%m-%d'); ?></td>
									<td>
                                        <?php 
											echo "<select name='outlet_".$row->profile_id."' id='outlet_".$row->profile_id."'>";
											echo "<option value='0' selected>Please chose outel </option>";	
											
											foreach($this->outlet as $k => $v){
												echo "<option value='".$v->value."'";
												echo ($v->value == $row->pick_up_at)?'selected':'';
												echo ">$v->text</option>";
											}
											echo "</select>";
										?>
                                    </td>
									<td style="width: 100px;" align="right">
										<div class="loading" id="loading_<?php echo $row->profile_id;?>" style="display: none;float:left; width: 30px;"><img src="<?php echo JURI::root();?>images/loading.gif" style="margin-top: 0;" /></div>
										<span id="save_<?php echo $row->profile_id;?>" style="margin-right: 8px;background: #FFF;display:none;"></span>
										<a class="svoucher svoucher_<?php echo $row->outlet ?>" rel="<?php echo $row->profile_id ?>"  name="svoucher" onclick="">Save</a>
									</td>
                                 </tr>
                             <?php 
                                 $k = 1 - $k ;     
                                 endfor; 
                                 endif; 
                             ?>
                         </tbody>
                     <tfoot>
                        <tr>
                            <td colspan="16">
                                <?php
                                     echo $this->pagination->getListFooter();
                                ?>
                            </td>
                        </tr>
                    </tfoot>                       
                </table>
                <input type="hidden" name="controller" value="reports" />
                <input type="hidden" name="option" value="com_wrd" />
                <input type="hidden" name="task" value="membershipclubdetail" />
                <input type="hidden" name="boxchecked" value="0" />
                <?php echo JHTML::_( 'form.token' ); ?>
            </form>
        </div>
        
</div>
<?php 
    //$this->downloadFileExcel();
?>